$(function(){
    /*黑白库中页面右上角三级联动*/
     $(".selectList").each(function(){
            var url = "json/area.json";
            var areaJson;
            var temp_html;
            var oProvince = $(this).find(".province");
            var oCity = $(this).find(".city");
            var oDistrict = $(this).find(".district");
            //初始化年
            var province = function(){
                $.each(areaJson,function(i,province){
                    temp_html+="<option value='"+province.p+"'>"+province.p+"</option>";
                });
                oProvince.html(temp_html);
                city();
            };
            //赋值颜色
            var city = function(){
                temp_html = ""; 
                var n = oProvince.get(0).selectedIndex;
                $.each(areaJson[n].c,function(i,city){
                    temp_html+="<option value='"+city.ct+"'>"+city.ct+"</option>";
                });
                oCity.html(temp_html);
                district();
            };
            //赋值期数
            var district = function(){
                temp_html = ""; 
                var m = oProvince.get(0).selectedIndex;
                var n = oCity.get(0).selectedIndex;
                if(typeof(areaJson[m].c[n].d) == "undefined"){
                    oDistrict.css("display","none");
                }else{
                    oDistrict.css("display","inline");
                    $.each(areaJson[m].c[n].d,function(i,district){
                        temp_html+="<option value='"+district.dt+"'>"+district.dt+"</option>";
                    });
                    oDistrict.html(temp_html);
                };
            };
            //选择年改变颜色
            oProvince.change(function(){
                city();
            });
            //选择颜色改变期数
            oCity.change(function(){
                district();
            });
            //获取json数据
            $.getJSON(url,function(data){
                areaJson = data;
                province();
            });
        });
     
     
     
     
     
     
     /*图库扫描选择年份期数*/
     $(".selectScan").each(function(){
            var url = "json/scan.json";
            var areaJson;
            var temp_html;
            var oProvince = $(this).find(".province");
            var oCity = $(this).find(".city");
            var oDistrict = $(this).find(".district");
            //初始化年
            var province = function(){
                $.each(areaJson,function(i,province){
                    temp_html+="<option value='"+province.p+"'>"+province.p+"</option>";
                });
                oProvince.html(temp_html);
                city();
            };
            //赋值颜色
            var city = function(){
                temp_html = ""; 
                var n = oProvince.get(0).selectedIndex;
                $.each(areaJson[n].c,function(i,city){
                    temp_html+="<option value='"+city.ct+"'>"+city.ct+"</option>";
                });
                oCity.html(temp_html);
            };
            //选择年改变颜色
            oProvince.change(function(){
                city();
            });
            //获取json数据
            $.getJSON(url,function(data){
                areaJson = data;
                province();
            });
        });


    });



//后台模板扫描按钮ajax请求
function scanTemplate(tempColour){
	var scanNurl="";
	if('col'==tempColour){
		scanNurl="/baUser/scanPic/col.do";
	}else{
		scanNurl="/baUser/scanPic/black.do";
	}
	
	var scanYear=$("#scanYear").val();
	var scanPeriods=$("#scanPeriods").val();
	if("请选择"==scanYear||"请选择"==scanPeriods){
		alert('请选择需要的年份和期数!');
		return false;
	}
	//调用遮罩层
	shade();
		/*//获取工程名称
		 var pathName=window.document.location.pathname;
		 var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);*/
		$.ajax({
			type:"post", //提交的类型
			url: path+scanNurl,//提交地址
			data: {
			    "years":scanYear,
			    "periods":scanPeriods,
			   },
		    dataType: 'json',
			success: function(data){ //回调方法
				/*var data=datas.substring(0,1);*/
				if('1'==data){
					//点击关闭按钮的时候，遮罩层关闭
					$("#bg,.box").css("display", "none");
					alert('数据扫描成功!');
				}
				if('0'==data){
					//点击关闭按钮的时候，遮罩层关闭
					$("#bg,.box").css("display", "none");
					alert('数据扫描失败!');
				}
			}
			});
}


